from impoter_bag import *

ua_pool = {
    # 浏览器的UA标识是：开头冒充Mozilla，接下来系统版本号，接下来就是叠的各个标识(冒充其他浏览器)
    # Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0
    'Mozilla': ['5.0'],
    'os_info': [
        'Windows NT 10.0; Win64; x64',
        'Windows NT 6.3; Trident/7.0; rv 11.0',
        'Windows NT 10.0; Win64; x64; rv:97.0'
    ],
    'Gecko': ['(KHTML, like Gecko)',
              'Gecko/20100101'],
    'AppleWebKit': ['', '537.36'],
    'self_': {
        'Chrome': ['46.0.2486.0',
                   '97.0.4692.99',
                   '70.0.3538.16',
                   '70.0.3538.67',
                   '70.0.3538.97',
                   '71.0.3578.137',
                   '71.0.3578.30',
                   '71.0.3578.33',
                   '71.0.3578.80',
                   '72.0.3626.69',
                   '72.0.3626.7',
                   '73.0.3683.20',
                   '73.0.3683.68',
                   '74.0.3729.6',
                   '75.0.3770.140',
                   '75.0.3770.8',
                   '75.0.3770.90',
                   '76.0.3809.12',
                   '76.0.3809.126',
                   '76.0.3809.25',
                   '76.0.3809.68',
                   '77.0.3865.10',
                   '77.0.3865.40',
                   '78.0.3904.105',
                   '78.0.3904.11',
                   '78.0.3904.70',
                   '79.0.3945.16',
                   '79.0.3945.36',
                   '80.0.3987.106',
                   '80.0.3987.16',
                   '81.0.4044.138',
                   '81.0.4044.20',
                   '81.0.4044.69',
                   '83.0.4103.14',
                   '83.0.4103.39',
                   '84.0.4147.30',
                   '85.0.4183.38',
                   '85.0.4183.83',
                   '85.0.4183.87',
                   '86.0.4240.22',
                   '87.0.4280.20',
                   '87.0.4280.87',
                   '87.0.4280.88',
                   '88.0.4324.27',
                   '88.0.4324.96',
                   '89.0.4389.23',
                   '90.0.4430.24',
                   '91.0.4472.101',
                   '91.0.4472.19',
                   '92.0.4515.107',
                   '92.0.4515.43',
                   '93.0.4577.15',
                   '93.0.4577.63',
                   '94.0.4606.113',
                   '94.0.4606.41',
                   '94.0.4606.61',
                   '95.0.4638.10',
                   '95.0.4638.17',
                   '95.0.4638.54',
                   '95.0.4638.69',
                   '96.0.4664.18',
                   '96.0.4664.35',
                   '96.0.4664.45',
                   '97.0.4692.20',
                   '97.0.4692.36',
                   '97.0.4692.71',
                   '98.0.4758.48',
                   '98.0.4758.80',
                   '99.0.4844.17', ],
        'Firefox': ['97.0'],
    },
    'Safari': ['', '537.36'],
    'other': ['', 'Edge/13.10586'],
}


def get_ua():
    ua = ''
    ua += 'Mozilla' + '/' + random.choice(ua_pool['Mozilla']) + ' '
    ua += f'({random.choice(ua_pool["os_info"])})' + ' '
    index = random.randrange(0, len(ua_pool['AppleWebKit']))
    ua += '' if not index else 'AppleWebKit' + '/' + ua_pool['AppleWebKit'][index] + ' '
    ua += f'{random.choice(ua_pool["Gecko"])}' + ' '
    val = random.choice(list(ua_pool['self_']))
    ua += val + '/' + random.choice(ua_pool['self_'][val]) + ' '
    index = random.randrange(0, len(ua_pool['Safari']))
    ua += '' if not index else 'Safari' + '/' + ua_pool['Safari'][index]
    ua += ' ' + random.choice(ua_pool['other'])
    return {'User-Agent': ua.strip()}


if __name__ == '__main__':
    print(get_ua())
